from django.db import models
from User.models import *
from goods.models import *
# Create your models here.
class CartItem(models.Model):
    goodsid=models.IntegerField()
    colorid=models.IntegerField()
    sizeid=models.IntegerField()
    count=models.PositiveIntegerField()
    user=models.ForeignKey(User,on_delete=models.CASCADE)
    isdelete=models.BooleanField(default=False)
    class Meta:
        unique_together=['goodsid','sizeid','colorid','user']

    def goods(self):
        return Goods.objects.get(id=self.goodsid)
    def color(self):
        return Color.objects.get(id=self.colorid)
    def size(self):
        return Size.objects.get(id=self.sizeid)

    def totalPrice(self):
        return int(self.count) * float(self.goods().price)



